package com.weetop.cfw.kind.adapter

import android.view.LayoutInflater
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.coorchice.library.SuperTextView
import com.weetop.cfw.R
import com.weetop.cfw.bean.LeaseSaleBrowsingRecordBean
import com.weetop.cfw.bean.TestBean
import com.weetop.cfw.bean.WorkshopWarehouseDetailBean
import com.weetop.cfw.constants.UrlConstants
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout

class WorkshopDetailAdapter(layoutId:Int,dataList:List<WorkshopWarehouseDetailBean.ReldataBean>):BaseQuickAdapter<WorkshopWarehouseDetailBean.ReldataBean,BaseViewHolder>(layoutId,dataList) {
    override fun convert(helper: BaseViewHolder, item:WorkshopWarehouseDetailBean.ReldataBean?) {
        val textWorkshopImg = helper.getView<SuperTextView>(R.id.textWorkshopImg)
        val flowWorkshopDesc: TagFlowLayout = helper.getView(R.id.flowWorkshopDesc)
        val tagList = ArrayList<String?>()
        val tagListOther = ArrayList<String>()
        tagList.add(item?.isalone)
        tagList.add(item?.haslift)
        if(item?.floor?.endsWith("层")!!){
            tagList.add("${item.floor}层")
        }else{
            tagList.add(item.floor)
        }
        for(itemTag in tagList){
            if(itemTag?.isNotBlank()!!){
                tagListOther.add(itemTag)
            }
        }
        flowWorkshopDesc.adapter = object: TagAdapter<String>(tagListOther){
            override fun getView(parent: FlowLayout?, position: Int, t: String?): View {
                val textItemWorkshopDescFlowLayoutView = LayoutInflater.from(mContext).inflate(R.layout.layout_item_workshop_desc_flow,parent,false)
                val textItemWorkshopDesc = textItemWorkshopDescFlowLayoutView.findViewById<SuperTextView>(R.id.textItemWorkshopDesc)
                textItemWorkshopDesc.text = tagListOther[position]
                return textItemWorkshopDescFlowLayoutView
            }
        }
        textWorkshopImg.setUrlImage("${UrlConstants.baseUrl}${item?.imgurl}")
        helper.setText(R.id.textWorkshopName,item?.title).setText(R.id.textWorkshopAddress,"地址：${item?.address}")
            .setText(R.id.textWorkshopArea,"面积：${item?.area}㎡")
    }
}